﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExtensionControls
{
    public class PersonViewModel : IViewModel<EPersonColumn>
    {
        private Person _Person;

        public PersonViewModel()
        {
            this._Person = new Person();
        }

        public PersonViewModel(Person Person)
        {
            this._Person = Person;
        }

        public List<object> getColumns(List<EPersonColumn> columns)
        {
            List<object> returnColumns = new List<object>();

            returnColumns.Add(this);
            foreach (EPersonColumn column in columns)
            {
                switch (column)
                {
                    case EPersonColumn.NAME:
                        returnColumns.Add(this._Person.Name.ToString());
                        break;
                    case EPersonColumn.SURNAME:
                        returnColumns.Add(this._Person.Surname.ToString());
                        break;
                    case EPersonColumn.MAN:
                        returnColumns.Add(this._Person.Man);
                        break;
                    case EPersonColumn.CITY:
                        List<KeyValuePair<string, bool>> data = new List<KeyValuePair<string, bool>>();
                        data.Add(new KeyValuePair<string, bool>("", false));
                        data.Add(new KeyValuePair<string, bool>("Suwałki", this._Person.City.Equals("Suwałki")));
                        data.Add(new KeyValuePair<string, bool>("Gdańsk",  this._Person.City.Equals("Gdańsk")));
                        returnColumns.Add(data);
                        break;
                }
            }

            return returnColumns;
        }

        public void UpdateData(List<EPersonColumn> columnTypes, List<object> data)
        {
            for (int i = 0; i < data.Count; i++)
            {
                switch (columnTypes[i])
                {
                    case EPersonColumn.NAME:
                        this._Person.Name = (string)data[i];
                        break;
                    case EPersonColumn.SURNAME:
                        this._Person.Surname = (string)data[i];
                        break;
                    case EPersonColumn.MAN:
                        this._Person.Man = (bool)data[i];
                        break;
                    case EPersonColumn.CITY:
                        this._Person.City = (string)data[i];
                        break;
                }
            }
        }

        public string SayHello()
        {
            return this._Person.SayHello();
        }
    }
}
